package com.cbl.v.ssczs.view.fragment;


import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.GridView;

import com.cbl.v.ssczs.R;
import com.cbl.v.ssczs.mode.entity.LocalDataBean;
import com.cbl.v.ssczs.view.adapter.StyleHGridAdapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends BaseFragment {
    @BindView(R.id.gv_item)
    GridView gvItem;
    private List<LocalDataBean> fcList;
    private List<LocalDataBean> tcList;
    private List<LocalDataBean> gpcList;

    private List<String> fcTitleList;
    private List<String> fcUrlList;
    private List<String> fcTimeList;
    private List<Integer> fcIconList;

    private List<String> tcTitleList;
    private List<String> tcUrlList;
    private List<String> tcTimeList;
    private List<Integer> tcIconList;

    private List<String> gpcTitleList;
    private List<String> gpcUrlList;
    private List<String> gpcTimeList;

    private List<LocalDataBean> localList;
    private StyleHGridAdapter localAdapter;

    @Override
    protected int getLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView(View view) {
        fcList = new ArrayList<>();
        tcList = new ArrayList<>();
        gpcList = new ArrayList<>();

        fcTitleList = new ArrayList<>();
        fcUrlList = new ArrayList<>();
        fcTimeList = new ArrayList<>();
        fcIconList = new ArrayList<>();

        tcTitleList = new ArrayList<>();
        tcUrlList = new ArrayList<>();
        tcTimeList = new ArrayList<>();
        tcIconList = new ArrayList<>();

        gpcTitleList = new ArrayList<>();
        gpcUrlList = new ArrayList<>();
        gpcTimeList=new ArrayList<>();

        localList = new ArrayList<>();
        localAdapter = new StyleHGridAdapter(getContext(), localList);
        gvItem.setAdapter(localAdapter);
    }

    @Override
    protected void initData() {
        Collections.addAll(fcTitleList, "双色球",
                "福彩3D",
                "七乐彩");
        Collections.addAll(fcUrlList,
                "http://f.apiplus.net/ssq-20.json",
                "http://f.apiplus.net/fc3d-20.json",
                "http://f.apiplus.net/qlc-20.json");
        Collections.addAll(fcTimeList,
                "21:15开奖",
                "21:15开奖",
                "21:15开奖");
        Collections.addAll(fcIconList,
                R.mipmap.ic_ssq,
                R.mipmap.ic_3d,
                R.mipmap.ic_qlc);
        for (int i = 0; i < fcTitleList.size(); i++) {
            LocalDataBean bean = new LocalDataBean();
            bean.setTitle(fcTitleList.get(i));
            bean.setUrlAddress(fcUrlList.get(i));
            bean.setTime(fcTimeList.get(i));
            bean.setIcon(fcIconList.get(i));
            fcList.add(bean);
        }
        getData(1);

        Collections.addAll(tcTitleList,
                "大乐透",
                "七星彩",
                "排列三",
                "排列五");
        Collections.addAll(tcUrlList,
                "http://f.apiplus.net/dlt-20.json",
                "http://f.apiplus.net/qxc-20.json",
                "http://f.apiplus.net/pl3-20.json",
                "http://f.apiplus.net/pl5-20.json"
        );
        Collections.addAll(tcTimeList,
                "20:30开奖",
                "20:30开奖",
                "20:30开奖",
                "20:30开奖");
        Collections.addAll(tcIconList,
                R.mipmap.ic_dlt,
                R.mipmap.ic_qxc,
                R.mipmap.ic_pl3,
                R.mipmap.ic_pl5);
        for (int i = 0; i < fcTitleList.size(); i++) {
            LocalDataBean bean = new LocalDataBean();
            bean.setTitle(tcTitleList.get(i));
            bean.setUrlAddress(tcUrlList.get(i));
            bean.setTime(tcTimeList.get(i));
            bean.setIcon(tcIconList.get(i));
            tcList.add(bean);
        }

        Collections.addAll(gpcTitleList,
                "黑龙江时时彩",
                "内蒙古时时彩",
                "天津时时彩",
                "新疆时时彩",
                "云南时时彩",

                "安徽11选5",
                "北京11选5",
                "福建11选5",
                "广东11选5",
                "甘肃11选5",
                "广西11选5",
                "贵州11选5",
                "河北11选5",
                "湖北11选5",
                "吉林11选5",
                "江苏11选5",
                "江西11选5",
                "辽宁11选5",
                "内蒙古11选5",
                "山东11选5",
                "上海11选5",
                "陕西11选5",
                "山西11选5",
                "天津11选5",
                "新疆11选5",
                "云南11选5",

                "安徽快三",
                "北京快三",
                "福建快三",
                "甘肃快三",
                "广西快三",
                "贵州快三",
                "河北快三",
                "湖北快三",
                "吉林快三",
                "江苏快三",
                "江西快三",
                "内蒙古快三",
                "上海快三"
                );
        Collections.addAll(gpcUrlList,
                "http://f.apiplus.net/hljssc-20.json",
                "http://f.apiplus.net/nmgssc-20.json",
                "http://f.apiplus.net/tjssc-20.json",
                "http://f.apiplus.net/xjssc-20.json",
                "http://f.apiplus.net/ynssc-20.json",

                "http://f.apiplus.net/ah11x5-20.json",
                "http://f.apiplus.net/bj11x5-20.json",
                "http://f.apiplus.net/fj11x5-20.json",
                "http://f.apiplus.net/gd11x5-20.json",
                "http://f.apiplus.net/gs11x5-20.json",
                "http://f.apiplus.net/gx11x5-20.json",
                "http://f.apiplus.net/gz11x5-20.json",
                "http://f.apiplus.net/heb11x5-20.json",
                "http://f.apiplus.net/hub11x5-20.json",
                "http://f.apiplus.net/jl11x5-20.json",
                "http://f.apiplus.net/js11x5-20.json",
                "http://f.apiplus.net/jx11x5-20.json",
                "http://f.apiplus.net/ln11x5-20.json",
                "http://f.apiplus.net/nmg11x5-20.json",
                "http://f.apiplus.net/sd11x5-20.json",
                "http://f.apiplus.net/sh11x5-20.json",
                "http://f.apiplus.net/sxl11x5-20.json",
                "http://f.apiplus.net/sxr11x5-20.json",
                "http://f.apiplus.net/tj11x5-20.json",
                "http://f.apiplus.net/xj11x5-20.json",
                "http://f.apiplus.net/yn11x5-20.json",

                "http://f.apiplus.net/ahk3-20.json",
                "http://f.apiplus.net/bjk3-20.json",
                "http://f.apiplus.net/fjk3-20.json",
                "http://f.apiplus.net/gsk3-20.json",
                "http://f.apiplus.net/gxk3-20.json",
                "http://f.apiplus.net/gzk3-20.json",
                "http://f.apiplus.net/hebk3-20.json",
                "http://f.apiplus.net/hubk3-20.json",
                "http://f.apiplus.net/jlk3-20.json",
                "http://f.apiplus.net/jsk3-20.json",
                "http://f.apiplus.net/jxk3-20.json",
                "http://f.apiplus.net/nmgk3-20.json",
                "http://f.apiplus.net/shk3-20.json"

        );
        for (int i = 0; i < gpcTitleList.size(); i++) {
            LocalDataBean bean = new LocalDataBean();
            bean.setTitle(gpcTitleList.get(i));
            bean.setUrlAddress(gpcUrlList.get(i));
            if (gpcTitleList.get(i).contains("时时彩")){
                bean.setIcon(R.mipmap.ic_ssc);
                bean.setTime("10分钟一期");
            }else if (gpcTitleList.get(i).contains("11选5")){
                bean.setIcon(R.mipmap.ic_11x5);
                bean.setTime("10分钟一期");
            }else if (gpcTitleList.get(i).contains("快三")){
                bean.setIcon(R.mipmap.ic_ks);
                bean.setTime("10分钟一期");
            }
            gpcList.add(bean);
        }
    }

    @Override
    protected void initListener() {

    }

    @OnClick({R.id.rbt_fc, R.id.rbt_tc, R.id.rbt_gpc})
    public void onMyOnclick(View view) {
        switch (view.getId()) {
            case R.id.rbt_fc:
                getData(1);
                break;
            case R.id.rbt_tc:
                getData(2);
                break;
            case R.id.rbt_gpc:
                getData(3);
                break;
        }
    }

    private void getData(int type) {
        switch (type) {
            case 1:
                localList.clear();
                localList.addAll(fcList);
                localAdapter.notifyDataSetChanged();
                break;
            case 2:
                localList.clear();
                localList.addAll(tcList);
                localAdapter.notifyDataSetChanged();
                break;
            case 3:
                localList.clear();
                localList.addAll(gpcList);
                localAdapter.notifyDataSetChanged();
                break;
        }
    }


}
